package com.ruoyi.task.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.task.domain.TaskSub;
import com.ruoyi.task.domain.dto.TaskInfoDTO;
import com.ruoyi.task.domain.vo.TaskInfoVO;
import com.ruoyi.task.service.TaskSubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/tasksub")
public class TaskSubController extends BaseController {
    @Autowired
    private TaskSubService taskSubService;

    @PostMapping("/sub")
    public AjaxResult submitTaskSub(@RequestBody TaskSub taskSub) {
        return toAjax(taskSubService.submitTask(taskSub));
    }

    //分页查询 任务完成的情况
    @GetMapping("/sub")
    public TableDataInfo getTaskSub(TaskInfoDTO taskInfoVO) {
        startPage();
        List<TaskInfoVO> list = taskSubService.gettaskInfo(taskInfoVO);
        return getDataTable(list);
    }

    @PostMapping("/download-zip")
    public void downloadZip(@RequestBody List<Integer> ids, HttpServletResponse response) {
//HttpServletResponse 直接输出到 HTTP 响应流中。Spring 框架的 HttpServletResponse 允许开发者直接操作响应流进行数据输出，而不需要通过返回值。
        taskSubService.exportFile(ids,response);
    }

}
